package controller;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import model.Sprite;
import model.SpriteType;

public class TunnelShiftSpriteFactory {
	static SpriteType rockMaster;
	static SpriteType heroMaster;
	static{
		try{
			rockMaster=new SpriteType("../data/image/rock.png");
			heroMaster=new SpriteType("../data/image/hero.png");
		}catch (IOException ioe) {
			System.out.println("TunnelShiftSpriteFactory: fail to load images");
		}
	}
	
	public static Set<Sprite> getCompleteWall(int width,int height){
		Set<Sprite> sprites = new HashSet<Sprite>();
		int heightDecal = rockMaster.getHeight();
		
		for(int ii=0;ii*heightDecal<height;ii++){
			Sprite s=new Sprite(rockMaster);
			//s.setPosition(ii*10, 400-25);
			s.setPosition(width,ii*heightDecal);
			sprites.add(s);
		}
		
		return sprites;
	}
	public static Set<Sprite> getPartialWall(int width,int height,List<int[]> wallParts){
		Set<Sprite> sprites = new HashSet<Sprite>();
		
		for (int[] part : wallParts) {
			int partHeight = part[1]-part[0];
			if(rockMaster.getHeight()/2. < partHeight && partHeight < rockMaster.getHeight()){
				Sprite s=new Sprite(rockMaster);
				int h = (int)(part[0]-((rockMaster.getHeight()-partHeight)/2.));
				s.setPosition(width,h);
				sprites.add(s);
			}else{
				int numRock = (int)Math.ceil((float)(partHeight-rockMaster.getHeight())/rockMaster.getHeight());
				float step = (partHeight-rockMaster.getHeight())/numRock;
				float h = part[0];
				while(h<part[1]-0.1){
					Sprite s=new Sprite(rockMaster);
					s.setPosition(width, (int)h);
					sprites.add(s);
					h+=step;
				}
			}
		}
		
		return sprites;
	}
	
	public static Sprite getHero(){
		return new Sprite(heroMaster);
	}

	public static Sprite getRock(){
		return new Sprite(rockMaster);
	}
	
	public static int getWallWidth(){
		return rockMaster.getWidth();
	}
}
